package com.heima.schedule.client;

import com.heima.model.schedule.dtos.Task;
import com.heima.schedule.service.TaskService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 相当于controller
 */
@RestController
@RequestMapping("/api/v1/schedule")
public class ScheduleClient {

    @Autowired
    private TaskService taskService;

    /**
     * 添加任务
     * @param task   任务对象
     * @return       任务id
     */
    @PostMapping("/addTask")
    public void addTask(@RequestBody Task task){
        taskService.addTask(task);
    }

    /**
     * 拉取任务，消费任务
     * @param taskType 类型
     * @param priority 优先级
     * @return
     */
    @GetMapping("/pull/{taskType}/{priority}")
    public Task pullTask(@PathVariable Integer taskType,@PathVariable Integer priority){
        return taskService.pullTask(taskType,priority);
    }
}
